package com.tsw.project.controller;



import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.tsw.project.eneity.User;
import com.tsw.project.service.UserService;
import com.tsw.project.mapper.UserMapper;


@RestController
@RequestMapping("/api/v1/user")
public class UserController {


    @Autowired
    private UserService userService;

    @Autowired
    private UserMapper userMapper;


    /**
     * 功能描述: user 保存接口
     */
    @GetMapping("add")
    public Object add(){

        User user = new User();
        user.setAge(11);
        user.setUsername("张三");
        user.setPhone("1880177");
        int id = userService.add(user);

        return id;
    }


    @GetMapping("findAll")
    public Object findAll(){

        return userMapper.getAll();
    }

    /**
     * 查找单个用户
     */
    @GetMapping("find_by_id")
    public Object findById(long id){
        return userMapper.findById(id);
    }

    /**
     * 删除单个用户
     */
    @GetMapping("del_by_id")
    public Object delById(long id){
        userMapper.delete(id);
        return "";
    }

    /**
     *更新用户
     */
    @GetMapping("update")
    public Object update( String name,  Integer  id){
        User user = new User();
        user.setUsername(name);
        user.setUid(id);
        userMapper.update(user);
        return "";
    }
}
